<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/web/ui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/web/ui/css/public.css" media="all">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
    <script src="/web/js/vue2.js"></script>
    <script src="/web/js/axios.min.js"></script>
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body>

<div id="app">
    <el-form ref="form" :model="form" label-width="80px">
        <input type="hidden" v-model="form.id">
        <el-form-item label="订单名称（中文）">
            <el-input v-model="form.nameZh"></el-input>
        </el-form-item>
        <el-form-item label="订单名称（英文）">
            <el-input v-model="form.nameEn"></el-input>
        </el-form-item>
        <el-form-item label="发布日期">
            <el-date-picker style="width: 40%" type="text" disabled v-model="form.createTime"/>
        </el-form-item>
        <el-form-item label="订单分类">
            <el-select v-model="form.type" placeholder="请选择类别">
                <el-option label="书籍类" value="书籍类"></el-option>
                <el-option label="军工类" value="军工类"></el-option>
                <el-option label="日用品类" value="日用品类"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="订单数量">
            <el-input disabled v-model="form.orderCount"></el-input>
        </el-form-item>
        <el-form-item label="企业名称">
            <el-input disabled v-model="form.firmName"></el-input>
        </el-form-item>

        <el-form-item label="是否推荐">
            <el-radio-group v-model="form.isRecommend">
                <el-radio label="推荐">推荐</el-radio>
                <el-radio label="不推荐">不推荐</el-radio>
            </el-radio-group>
        </el-form-item>

        <el-form-item label="订单摘要">
            <el-input type="textarea" v-model="form.smInfo"></el-input>
        </el-form-item>

        <el-form-item label="订单图片（最多上传3张）">
            <el-upload
                    class="upload-demo"
                    action="http://localhost:8800/file/upload/commence"
                    :on-success="uploadSuccess"
                    list-type="picture"
                    :limit="limit"
            >

                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
            </el-upload>
            <img style="width: 10%" v-if="form.picPath" :src="form.picPath">
        </el-form-item>

        <el-form-item label="详细介绍">
            <el-input type="textarea" v-model="form.detailInfo"></el-input>
        </el-form-item>


        <el-form-item>
            <el-button type="primary" @click="doSubmit">修改</el-button>
            <el-button @click="doCancel">取消</el-button>
        </el-form-item>

    </el-form>
</div>

<script src="/web/ui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>

<script>

    const vm = new Vue({
        el: "#app",
        data() {
            return {
                limit: 1,
                form: {
                    id:"",
                    nameZh:"",
                    nameEn:"",
                    type:"",
                    orderCount:"",
                    firmName:"",
                    isRecommend:"",
                    smInfo:"",
                    picPath1:"",
                    picPath2:"",
                    picPath3:"",
                    detailInfo:"",
                    createTime:"",
                },
            }
        },
        methods: {
            uploadSuccess(res, file, fileList) {
                // console.log(res.data);
                this.form.picPath = res.data;
                axios.post("/firm/vip/updatePic", {
                    id: this.form.vipId,
                    picPath: this.form.picPath
                });
            },
            doSubmit() {
                // 关闭当前页面
                window.close();
                this.handleUpdate();
                // console.log(this.form.type);

                // 刷新父页面
                window.parent.location.reload();
            },
            doCancel() {
                window.close();
                // 刷新父页面
                window.parent.location.reload();
            },
            // 更新
            handleUpdate() {
                axios.post("/commence/update", this.form)
            }
        },
        async mounted() {
            const commence = JSON.parse(localStorage.getItem("t"));

            console.log("@@@")
            console.log(commence);
            this.form=commence;


            // console.log(this.form.createTime);
            localStorage.removeItem("t");
        }
    });


</script>
</body>
</html>